package xyz.heyaoshare.core.enums.system.user;

import lombok.AllArgsConstructor;
import lombok.Getter;
import xyz.heyaoshare.utils.ArrayUtils;

import java.util.Arrays;
import java.util.List;

import static xyz.heyaoshare.exceptions.code.ErrorInfo.ENUM_TYPE_NOT_EXIST;
import static xyz.heyaoshare.exceptions.customize.ServerException.exception;

/**
 * 用户状态
 * @author YueHe
 * @version 0.0.1
 * @since 2025/6/25 上午11:50
 */
@Getter
@AllArgsConstructor
public enum UserStatusEnum {

    ENABLE(1, "正常"), DISABLE(0, "禁用");

    private final int value;
    private final String label;

    public static UserStatusEnum valueOf(Integer value) {
        if (value == null) return null;
        return ArrayUtils.firstMatch(item -> item.getValue() == value, UserStatusEnum.values());
    }

    public static String getLabel(Integer value) {
        UserStatusEnum genderEnum = valueOf(value);
        if (genderEnum != null) return genderEnum.getLabel();
        return "";
    }

    public static void validate(Integer value) {
        if (value != null) {
            UserStatusEnum userStatusEnum = valueOf(value);
            if (userStatusEnum != null) return;
        }
        throw exception(ENUM_TYPE_NOT_EXIST);
    }

    public static List<Integer> getValues() {
        return Arrays.stream(values()).map(UserStatusEnum::getValue).toList();
    }

}